<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="js/layui/css/layui.css">
</head>
<body>
<div style="height: 100%;width: 100%">

        <div style="margin-top: 20px;margin-left: 20px;">

            <button id="exportExcel" type="button" class="layui-btn"><i class="layui-icon">&#xe601;</i>导出Excel</button>
            <button id="exportExcel2" type="button" class="layui-btn"><i class="layui-icon">&#xe601;</i>导出Excel2</button>

        </div>

        <div style="margin-top: 20px;margin-left: 20px;">

            <input type="file" id="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" >

            <button id="importExcel" type="button" class="layui-btn"><i class="layui-icon">&#xe67c;</i>上传Excel</button>

        </div>



</div>

<script src="js/layui/jQuery3.4.1.js"></script>
<script src="js/layui/layui.all.js"></script>

<script>

    //导出 Excel
    $('#exportExcel').click(function () {
        window.location.href='/excel/export'
    })

    //导出 Excel
    $('#exportExcel2').click(function () {
        window.location.href='/excel/export2'
    })

    //上传 Excel
    $('#importExcel').click(function () {
        let file =  $('#file')[0].files[0]
        if(file != null){
            let form = new FormData();
            form.append("file",file)
            $.ajax({
                url:'/import/excel',
                type:'post',
                data:form,
                async: false,
                cache:false,
                processData:false,
                contentType:false,
                success:function (data) {
                    console.log(data.code);
                }
            })
        }else {
            layer.alert("请先选择要上传的Excel文件")
        }
    })


</script>

</body>
</html>